package ooday03;
//引用数据类型的演示：
public class RefArrayDemo {
    public static void main(String[] args) {
//引用和基本数组区别：
     /*
        //声明Dog类型数组dogs，包含3个元素，每个元素都是Dog类型，默认值是null
        Dog[] dogs = new Dog[3];
        //声明Chick类型数组chick，包含4个元素，每个元素都是Chick类型，默认值是null
        Chick[] chicks = new Chick[4];
        //声明Fish类型数组fish，包含2个元素，每个元素都是Fish类型，默认值是null
        Fish[] fish = new Fish[2];


        //基本数组类型：
        int[] a = new int[3];
        a[2] =100; //给基本数组赋值


        //引用数组类型：
        Dog[] dogs =new Dog[3];
        dogs[0] = new Dog("小黑",2,"黑");//引用数组的赋值 需要new对象


      */

        Dog[] dogs =new Dog[3];
        dogs[0] = new Dog("小黑",2,"黑");
        dogs[1] = new Dog("小白",1,"白");
        dogs[2] = new Dog("小灰",3,"灰");
        System.out.println(dogs[0].name);//输出第一只狗狗的名字
        dogs[1].age =4;//修改第二只狗狗的年龄
        System.out.println(dogs[1].age);
        dogs[2].swim();//第三只狗狗在游泳

        for (int i =0;i< dogs.length;i++){//遍历dogs数组
            System.out.println(dogs[i].name);//输出每只狗狗的名字
            dogs[i].eat();//每只狗狗在吃饭
        }
        System.out.println("-----------------------------");
        System.out.println();

        Chick[] chicks =new Chick[2];
        chicks[0] = new Chick("豆豆",2,"黄");
        chicks[1] = new Chick("小花",1,"白");
        for (int i=0;i< chicks.length;i++){
            System.out.println(chicks[i].age);
            chicks[i].layEggs();
        }
        System.out.println("-----------------------------");
        System.out.println();

        Fish[] fish = new Fish[3];
        fish[0] = new Fish("小红",1,"金色");
        fish[1] = new Fish("小橘",2,"橘色");
        fish[2] = new Fish("小橙",3,"橙红色");
        for (int i =0;i<fish.length;i++){
            System.out.println(fish[i].color);
            fish[i].swim();
        }
        System.out.println("----------------------------------");

        //见PolymorphicDemo

    }
}
